import React from 'react';
import {View, Text, StyleSheet} from 'react-native';
import {useTranslation} from 'react-i18next';
import {Switch} from '@ant-design/react-native';

export const LangSetting = () => {
  const {i18n} = useTranslation();

  const isEnglish = i18n.language === 'en';

  const handleSwitchChange = (value: boolean) => {
    const newLanguage = value ? 'en' : 'zh';
    i18n.changeLanguage(newLanguage);
  };

  return (
    <View style={styles.container}>
      <View style={styles.switchContainer}>
        <Text style={styles.languageLabel}>
          {isEnglish ? 'English' : '中文'}
        </Text>
        <Switch checked={isEnglish} onChange={handleSwitchChange} />
      </View>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    position: 'absolute',
    top: 20,
    right: 20,
    alignItems: 'center',
  },
  title: {
    fontSize: 18,
    marginBottom: 10,
  },
  switchContainer: {
    flexDirection: 'row',
    alignItems: 'center',
    gap: 10,
  },
  languageLabel: {
    fontSize: 16,
    color: '#333',
  },
});

export default LangSetting;
